<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>${empty customer ? '添加客户' : '编辑客户'} - 电动车销售系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/purchase.css">
    <style>
        .customer-form-container {
            max-width: 600px;
            margin: 0 auto;
            padding: 30px;
            background: white;
            border-radius: 10px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
        }

        .form-header {
            text-align: center;
            margin-bottom: 30px;
        }

        .form-header-icon {
            font-size: 2.5rem;
            margin-bottom: 15px;
            color: #4e73df;
        }
    </style>
</head>
<body>
<header class="dashboard-header">
    <div class="container">
        <div class="d-flex justify-content-between align-items-center">
            <div>
                <h1 class="h3 mb-0"><i class="bi bi-bicycle"></i> 电动车销售管理系统</h1>
                <p class="mb-0 opacity-75">客户信息管理</p>
            </div>
            <div class="d-flex align-items-center">
                <div class="me-3">
                    <span class="d-none d-md-inline">${currentUser.name}</span>
                    <div class="badge bg-light text-dark">
                        <i class="bi bi-person-circle me-1"></i> 系统管理员
                    </div>
                </div>
                <div class="dropdown">
                    <button class="btn btn-light rounded-circle p-1" type="button" data-bs-toggle="dropdown">
                        <i class="bi bi-gear fs-5"></i>
                    </button>
                    <ul class="dropdown-menu dropdown-menu-end">
                        <li><a class="dropdown-item" href="${pageContext.request.contextPath}/change_password.jsp"><i class="bi bi-lock me-2"></i> 修改密码</a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item text-danger" href="${pageContext.request.contextPath}/LogoutServlet"><i class="bi bi-box-arrow-right me-2"></i> 退出登录</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</header>

<div class="container my-5">
    <div class="customer-form-container">
        <div class="form-header">
            <i class="bi bi-${empty customer ? 'person-plus' : 'pencil'} form-header-icon"></i>
            <h2>${empty customer ? '添加新客户' : '编辑客户信息'}</h2>
            <p class="text-muted">${empty customer ? '填写客户信息以添加到系统' : '修改客户详细信息'}</p>
        </div>

        <form method="post" action="${pageContext.request.contextPath}/addcustomer">
            <c:if test="${not empty customer}">
                <input type="hidden" name="id" value="${customer.id}">
            </c:if>

            <div class="mb-3">
                <label for="name" class="form-label">客户姓名 <span class="text-danger">*</span></label>
                <input type="text" class="form-control form-control-lg" id="name" name="name"
                       value="${customer.name}" required>
            </div>

            <div class="mb-3">
                <label for="phone" class="form-label">联系电话 <span class="text-danger">*</span></label>
                <input type="tel" class="form-control form-control-lg" id="phone" name="phone"
                       value="${customer.phone}" required>
            </div>

            <div class="mb-4">
                <label for="address" class="form-label">联系地址 <span class="text-danger">*</span></label>
                <textarea class="form-control form-control-lg" id="address" name="address"
                          rows="3" required>${customer.address}</textarea>
            </div>

            <div class="d-grid gap-2">
                <button type="submit" class="btn btn-primary btn-lg">
                    <i class="bi bi-check-circle me-2"></i> ${empty customer ? '添加客户' : '更新信息'}
                </button>
                <a href="${pageContext.request.contextPath}/CustomerListServlet" class="btn btn-outline-secondary btn-lg">
                    <i class="bi bi-arrow-left me-2"></i> 返回列表
                </a>
            </div>
        </form>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>